/*!
 * 定义常量和公用函数
 */
//区分客户端类型
var ua = navigator.userAgent.toLowerCase();
var os = '';
if (/iphone|ipad|ipod/.test(ua)) {		   
	os = 'ios';
} else if (/android/.test(ua)) {		 
	os = 'android';
}	
// 调用OC
function openCustomURLinIFrame(src)
{
    var rootElm = document.documentElement;
    var newFrameElm = document.createElement("IFRAME");
    newFrameElm.setAttribute("src",src);
    rootElm.appendChild(newFrameElm);
    //remove the frame now
    newFrameElm.parentNode.removeChild(newFrameElm);
}

function calliOSFunction(functionName, args, successCallback, errorCallback)
{
    var url = "js2ios://";
    
    var callInfo = {};
    callInfo.functionname = functionName;
    if (successCallback)
    {
        callInfo.success = successCallback;
    }
    if (errorCallback)
    {
        callInfo.error = errorCallback;
    }
    if (args)
    {
        callInfo.args = args;
    }
    
    url += JSON.stringify(callInfo);
    openCustomURLinIFrame(encodeURI(url));
}

function onSuccess (ret)
{
    if (ret)
    {
        var obj = JSON.parse(ret);
        alert('onSuccess: '+ret);
    }
}

function onError (ret)
{
    if (ret)
    {
        var obj = JSON.parse(ret);
        alert('onError: '+ret);
    }
}

function yangsheng() {
	if(os=="ios"){
		calliOSFunction("yangsheng", [], "onSuccess", "onError");
	}else if(os="android"){
		window.jsInterface.invokeMethod("yangsheng");
	}
}

function pinggu() {
	if(os=="ios"){
		calliOSFunction("pinggu", [], "onSuccess", "onError");
	}else if(os="android"){
		window.jsInterface.invokeMethod("pinggu");
	}
}

function yjwy() {
	if(os=="ios"){
		calliOSFunction("yjwy", [], "onSuccess", "onError");
	}else if(os="android"){
		window.jsInterface.invokeMethod("yjwy");
	}
}